//
//  PersonBeforeLoginVC.m
//  EJLX
//
//  Created by adc on 15/11/17.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "PersonBeforeLoginVC.h"
#import "LoginVC.h"

#import "PublicNoticeVC.h"
#import "ShouYinDingDanViewController.h"
#import "ErWeiMaViewController.h"
@interface PersonBeforeLoginVC ()

@end

@implementation PersonBeforeLoginVC
-(void)viewWillAppear:(BOOL)animated{
    
  self.navigationController.navigationBarHidden = YES;
}

-(void)creatNav{
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, WIDE, 44)];
    navView.backgroundColor = RGB_COLOR(0x00c49f);
    [self.view addSubview:navView];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(10, 7, 30, 30);
    leftBtn.layer.cornerRadius = 20;
    [leftBtn setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal] ;
    [leftBtn addTarget:self action:@selector(backBtn) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:leftBtn];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-60, 7, 120, 30  )];
    title.text = @"个人中心";
    title.textAlignment = NSTextAlignmentCenter;
    title.textColor = [UIColor whiteColor];
    [navView addSubview:title];
    
}
-(void)backBtn{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self creatNav];
    
    self.titleArray =@[@"系统公告",@"我的订单",@"我要升级",@"操作手册",@"我的二维码"];
    self.imgArr = @[@"系统公告新",@"我的订单",@"我要升级",@"操作手册",@"我的二维码新"];
    self.navigationController.navigationBarHidden = NO;
    self.title = @"个人中心";
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDE, 400)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView setScrollEnabled:NO];
    [self.view addSubview:_tableView];
    UIView *headVC = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDE, 180)];
    headVC.backgroundColor = RGB_COLOR(0x00c49f);
    ;
    _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _loginBtn.frame = CGRectMake(WIDE/2-40, 10, 80, 80);
    _loginBtn.layer.cornerRadius = 40;
    _loginBtn.showsTouchWhenHighlighted = NO;
    [_loginBtn addTarget:self action:@selector(goToLoginVC) forControlEvents:UIControlEventTouchUpInside];
    [headVC addSubview:_loginBtn];

        [_loginBtn setImage:[UIImage imageNamed:@"未登录"] forState:UIControlStateNormal];
        
        UILabel *LB = [[UILabel alloc] initWithFrame:CGRectMake(0, 120, WIDE, 40 )];
        LB.text = @"欢迎使用一键联";
        LB.font = [UIFont systemFontOfSize:30];
    LB.textColor = [UIColor whiteColor];
        LB.textAlignment = NSTextAlignmentCenter;
        [headVC addSubview:LB];
  
    _tableView.tableHeaderView = headVC;
    
    
    if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}

-(void)goToLoginVC{
    LoginVC *login = [[LoginVC alloc] init];
    [self.navigationController pushViewController:login animated:YES];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.titleArray[indexPath.row];
    cell.textLabel.textColor = [UIColor blackColor];
    
    cell.imageView.image = [UIImage imageNamed:self.imgArr[indexPath.row]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row ==0) {
        //系统公告
        PublicNoticeVC *public = [[PublicNoticeVC alloc] init];
        [self.navigationController pushViewController:public animated:YES];
    }else if (indexPath.row == 1){
       //我的订单
//        ShouYinDingDanViewController *dingdan = [[ShouYinDingDanViewController alloc]  init];
//        [self.navigationController pushViewController:dingdan animated:YES];
        SHOW_ALERT(@"请先登录，才能查看个人订单")
        
        
    }else if (indexPath.row == 2){
        //我要升级
        [HttpsManager requsetGetVersionForAPPBlock:^(NSDictionary *dict) {
            NSString *version = [[dict objectForKey:@"data"] objectForKey:@"v_name"];
            
            NSString *currentVersion = [[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
            
            NSLog(@"current %@ \n version %@",currentVersion,version);
            if (version == NULL) {
                SHOW_ALERT(@"当前已是最新版本")
            }
            if (version>currentVersion) {
                NSString *str = [NSString stringWithFormat:@"发现新版本(%@),是否更新?",version];
                SHOW_ALERT(str)
                //点击更新
                
            }
        }];
   
    }
    else if (indexPath.row == 3){
        //操作手册
        GoToWebView *web = [[GoToWebView alloc] initWithurl:[NSURL URLWithString:[NSString stringWithFormat:@"%@comm/user_agreement",HTTPS_ID]] title:@"操作手册"];
        [self.navigationController pushViewController:web animated:YES];
    }else if (indexPath.row == 4){
        //我的二维码
        ErWeiMaViewController *wei = [[ErWeiMaViewController alloc] init];
        [self.navigationController pushViewController:wei  animated:YES];
        
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
